package n_swing_jtable;

import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;

public class JTableEx1 extends JInternalFrame {

	private static final long serialVersionUID = 1L;

	private JPanel jContentPane = null;
	JTable table;
	JScrollPane scroll;
	DefaultTableModel model;
	TableEventListener event;	
	JPanel panel;
	JButton appendBtn, deleteBtn, printBtn;


	public JTableEx1() {
		super("Sample1",true, true, true, false);
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(385, 265);
		this.setContentPane(getJContentPane());
		this.setTitle("JTableTest");
		this.setDefaultCloseOperation(JInternalFrame.HIDE_ON_CLOSE);
		
		String[] header = {"이름", "전화번호", "주소"};
		model = new DefaultTableModel(header,0);
		table = new JTable(model);
		scroll = new JScrollPane(table);
		
		panel = new JPanel();
		appendBtn = new JButton("Append");
		deleteBtn = new JButton("Delete");
		printBtn = new JButton("Print");
		
		event = new TableEventListener(table);
		appendBtn.addActionListener(event);
		deleteBtn.addActionListener(event);
		printBtn.addActionListener(event);
		
		panel.add(appendBtn);
		panel.add(deleteBtn);
		panel.add(printBtn);
		
		this.add(scroll, BorderLayout.CENTER);
		this.add(panel, BorderLayout.SOUTH);
		
		
	}

	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
		}
		return jContentPane;
	}

} 
